package org.lendoo.web.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.lendoo.web.enumeration.ServiceResultEnum;
import org.springframework.stereotype.Service;
import org.lendoo.web.mapper.InterfaceCallLogMapper;
import org.lendoo.web.entity.InterfaceCallLog;
import org.lendoo.web.service.InterfaceCallLogService;
import org.lendoo.web.pojo.common.ServiceResult;

import java.io.Serializable;
import java.util.List;

/**
 * InterfaceCallLogService接口的实现类
 */
@Slf4j
@Service
public class InterfaceCallLogServiceImpl extends ServiceImpl<InterfaceCallLogMapper, InterfaceCallLog> implements InterfaceCallLogService {

    /**
     * 新增
     * @param interfaceCallLog 接口调用日志
     * @return 添加成功返回1，添加失败返回-1
     */
    @Override
    public ServiceResult<Boolean> add(InterfaceCallLog interfaceCallLog) {
        baseMapper.insert(interfaceCallLog);
        return new ServiceResult<>(ServiceResultEnum.INSERT_SUCCESS.getCode(), Boolean.TRUE, Boolean.TRUE, ServiceResultEnum.INSERT_SUCCESS.getMessage());
    }

    /**
     * 批量导入
     * @param interfaceCallLogList 接口调用日志（列表）
     * @return 批量导入成功返回1，批量导入失败返回-1
     */
    @Override
    public ServiceResult<Boolean> batchAdd(List<InterfaceCallLog> interfaceCallLogList) {
        baseMapper.insertBatchSomeColumn(interfaceCallLogList);
        return new ServiceResult<>(ServiceResultEnum.INSERT_SUCCESS.getCode(), Boolean.TRUE, Boolean.TRUE, ServiceResultEnum.INSERT_SUCCESS.getMessage());
    }

    /**
     * 根据id更新
     * @param interfaceCallLog 接口调用日志
     * @return 更新成功返回1，更新失败返回-1
     */
    @Override
    public ServiceResult<Boolean> updateForId(InterfaceCallLog interfaceCallLog) {
        baseMapper.updateById(interfaceCallLog);
        return new ServiceResult<>(ServiceResultEnum.UPDATE_SUCCESS.getCode(), Boolean.TRUE, Boolean.TRUE, ServiceResultEnum.UPDATE_SUCCESS.getMessage());
    }

    /**
     * 根据id删除
     * @param id 主键
     * @return 删除成功返回1，删除失败返回-1
     */
    @Override
    public ServiceResult<Boolean> deleteById(Serializable id) {
        baseMapper.deleteById(id);
        return new ServiceResult<>(ServiceResultEnum.DELETE_SUCCESS.getCode(), Boolean.TRUE, Boolean.TRUE, ServiceResultEnum.DELETE_SUCCESS.getMessage());
    }

    /**
     * 根据id查询
     * @param id 主键
     * @return 返回查询结果
     */
    @Override
    public ServiceResult<InterfaceCallLog> selectById(Serializable id) {
        InterfaceCallLog interfaceCallLog = baseMapper.selectById(id);
        return new ServiceResult<>(ServiceResultEnum.SELECT_SUCCESS.getCode(), interfaceCallLog, Boolean.TRUE, ServiceResultEnum.SELECT_SUCCESS.getMessage());
    }

    /**
     * 根据条件，分页查询，升序/降序排列
     * @param interfaceCallLog 接口调用日志
     * @param pageNo 页号
     * @param pageSize 每页行数
     * @return 返回查询结果列表
     */
    @Override
    public ServiceResult<PageInfo<InterfaceCallLog>> page(InterfaceCallLog interfaceCallLog, int pageNo, int pageSize) {
        PageHelper.startPage(pageNo, pageSize);
        LambdaQueryWrapper<InterfaceCallLog> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        List<InterfaceCallLog> interfaceCallLogList = baseMapper.selectList(lambdaQueryWrapper);
        return new ServiceResult<>(ServiceResultEnum.SELECT_SUCCESS.getCode(), new PageInfo<>(interfaceCallLogList), Boolean.TRUE, ServiceResultEnum.SELECT_SUCCESS.getMessage());
    }
}
